/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.DragonPokerServer.Rules;

import java.util.ArrayList;
import org.DragonPokerServer.Classes.Card;
import org.DragonPokerServer.Classes.HandPlayer;
import org.DragonPokerServer.Classes.Points;
import org.DragonPokerServer.Thread.ThreadUser;

/**
 *
 * @author nykola
 */
public class TrisRule extends GenericRule {


    @Override
    public int processRequest(ArrayList<Card> cards, HandPlayer hp) {
        System.out.println("Rules: TrisRule");
        hp.setPoints(3);
        return 0;
    }

    @Override
    public boolean isToProcessing(ArrayList<Card> cards, HandPlayer hp) {
        if (checkCards(cards, hp.getCards()) == true) {
            return true;
        }
        else
            setNext(new DoublePairRule());
        return false;
    }


    public boolean checkCards(ArrayList<Card> tablecards, ArrayList<Card> playercards){
        ArrayList<Card> cards = new ArrayList<Card>();
        cards.add(playercards.get(0));
        cards.add(playercards.get(1));
        for (Card a : tablecards) {
            cards.add(a);
        }
        int[] cc = new int[13];

            for (int i = 0; i < cards.size(); i++)
            {
                cc[cards.get(i).getValue() - 1]++;
            }

        ArrayList tris = new ArrayList();

            for (int i = 0; i < 13; i++)
            {
                if (cc[i] == 3)
                {
                    tris.add(i + 1);
                }
            }

        if(tris.size() >= 1){
            return true;
        }

    return false;

    }

   @Override
   public ArrayList getWinners(ArrayList<Card> communityCards, ArrayList<HandPlayer> playerCards) {
      throw new UnsupportedOperationException("Not supported yet.");
   }


}
